/***************************************************************************
 *   Copyright (C) 2007 by Grzegorz Latarowski   *
 *   g.latarowski@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/



#ifndef WINDOW_H
#define WINDOW_H

// Qt
#include <QtGui>
#include <QSqlTableModel>

// autonet
#include "autopackets.h"

// local
#include "ui_window.h"
#include "eventsclient.h"
#include "gimageviewer.h"

class GConnectionWidget;


// -------------------------- Window{} ---------------------------------------
/// \brief Main window class.
// ---------------------------------------------------------------------------
class Window : public QMainWindow, protected Ui::Window
{
	Q_OBJECT
			
public:
	// ====================================================
	// constructor/destructor

	/// \brief Setups window.
	///
	/// Creates scene and adds it to view.
	Window();

	/// \brief Deletes window.
	virtual ~Window();


public slots:
		// ------------------------------------------------
		// connection
	void connectToHost( const QString & host );
	void disconnectFromHost();
	void hostDisconnected();
	void authorizationFailed( const QString & message );
	
protected slots:

	// ====================================================
	// actions

		// ------------------------------------------------
		// file manipulation

	/// \brief Creates new/empty configuration file.
	virtual void on_actionNew_triggered();
	/// \brief Opens configuration file.
	virtual void on_actionOpen_triggered();
	/// \brief Saves configuration file as.
	virtual void on_actionSaveAs_triggered();


		// ------------------------------------------------
		// downloading
	virtual void on_actionDownloadEvents_triggered();
	
		// ------------------------------------------------
		// state 
	
	void saveSettings();
	void restoreSettings();

protected:
	
	virtual void closeEvent( QCloseEvent * pEvent );

private slots:
	void itemClicked( const QModelIndex & index );
	
private:
	void connectedSetup();
	void openDatabase( const QString & baseFileName );
	void insertEvents( const QList< Event > & events );
	
	// ====================================================
	// camera related
	GEventsClient _eventsClient;

	// ====================================================
	// authorization 
	QString _lastLogin;

	// ====================================================
	// widgets
	GConnectionWidget * _pConnectionWidget;

	// ====================================================
	// status

	/// Shows \a message in status bar for 5000 mseconds, defaultly
	void message( const QString & message, int timeout = 5000 );
	
	
	QString          _baseFileName;
	QSqlTableModel * _pModel;

	GImageViewer * _pImageViewer;

	QTimer _downloadTimer;
	
}; // class !Window
// ---------------------------------------------------------------------------




#endif // !WINDOW_H






// eof
